﻿using SmartSapce.ServiceLocation;
using SmartSpace.Core;
using SmartSpace.Packaging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SmartSpace.WebApp._console.wizzard
{
    public partial class deploy_application_template : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ICoreService service = ServiceLocator.Get<ICoreService>();
            List<SiteTemplate> themes = service.GetSiteTemplates();
            if (themes != null && themes.Count > 0)
            {
                Response.Redirect("./create-application.aspx");
            }
        }

        protected void _ctlBtnSave_Click(object sender, EventArgs e)
        {
                ICoreService coreService = ServiceLocator.Get<ICoreService>();
                SiteTemplate theme = new SiteTemplate();
                theme.Id = Guid.NewGuid();
                theme.Code = _ctlEditCode.Text;
                theme.Caption = _ctlEditCaption.Text;
                theme.Name = _ctlEditCode.Text;
                theme.Package = _ctlEditCode.Text;
                theme.PreviewImageUrl = _ctlEditCode.Text;
                theme.Type = _ctlEditCode.Text;
                theme.Version = "1.0.0.0";
                if (coreService.SaveSiteTemplate(theme))
                {
                    Response.Redirect("./create-application.aspx");
                }
        }
    }
}